package com.itheima.service.db.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.db.BlackList;
import com.itheima.domain.db.UserInfo;
import com.itheima.vo.PageBeanVo;
import com.itheima.mapper.BlackListMapper;
import com.itheima.service.db.BlackListService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class BlackListServiceImpl implements BlackListService {

    @Autowired
    private BlackListMapper blackListMapper;

    //mybatis-plus分页查询
    @Override
    public PageBeanVo findBlackList(Long userId, Integer pageNum, Integer pageSize) {
        //1. 使用mybatisplus的分页插件实现分页查询
        Page<UserInfo> page = new Page<>(pageNum, pageSize);
        page = blackListMapper.findBlackListByUserId(page, userId);

        //2.page ==> pageBeanVo
        return new PageBeanVo(pageNum,pageSize,page.getTotal(),page.getRecords());
    }

    //移除黑名单
    @Override
    public void delete(Long userId, Long blackUserId) {
        QueryWrapper<BlackList> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",userId);
        wrapper.eq("black_user_id",blackUserId);
        blackListMapper.delete(wrapper);
    }
}
